﻿$(document).ready(function (){
    var isMouseDown = false;
    
    var BorrowDeadlineLabel = $('#BorrowDeadlineLabel');
    var huatiaoLeft = $('#huatiao').offset().left;
    var BorrowDeadline = $('#BorrowDeadline');

    var currentMonth = Number(BorrowDeadline.val());
    var huakuaiOffset=$('#huakuai').offset();
    var currentLeft = (currentMonth * (100 / 32)) +huakuaiOffset.left;

    setMoneth(computeMonth(currentLeft), {left:currentLeft});

    function computeMonth(currentLeft) {
        var left = currentLeft - huatiaoLeft;
        var month = Math.round(left / (100 / 32));
        return month;
    }

    function setMoneth(month,huakuaiNewOffset)
    {
        $(BorrowDeadlineLabel).text(month + "个月");
        $(BorrowDeadline).val(month);
        if (huakuaiNewOffset)
        {
            $('#huakuai').offset(huakuaiNewOffset)
        }
    }


    $('#huakuai').draggable({
        axis: "x", containment: "parent", drag: function (event, ui) {
            var month = computeMonth($(this).offset().left);
            setMoneth(month);
            TraceBorrowMoneyAndBorrowDeadline();
        }
    });
});